<?php

namespace app\home\controller;

use think\Controller;
use think\Request;
use think\Db;
use think\Session;

class Book extends Controller
{
    public function read($id)
    {
        $user_id = Session::get('user')['id'];
        $book_id = $id;
        $res = Db::table('mh_user_book')->insert(['user_id'=>$user_id,'book_id'=>$book_id]);

        if ($res){
            $info['status'] = true;
            $info['info'] = '添加成功';
        }else{
            $info['status'] = false;
            $info['info'] = '添加失败';
        }
        return json($info);
    }

    public function delete($id)
    {
        $user_id = Session::get('user')['id'];
        $book_id = $id;
        $res = Db::table('mh_user_book')->where(['user_id'=>$user_id,'book_id'=>$book_id])->delete();

        if ($res){
            $info['status'] = true;
            $info['info'] = '删除成功';
        }else{
            $info['status'] = false;
            $info['info'] = '删除失败';
        }
        return json($info);
    }
}
